<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('仪器信息列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <input type="text" name="deviceName" placeholder="请输入仪器名称" l/>
                            </li>
                            <li>
                                <input type="text" name="createPerson" placeholder="请输入创建人"/>
                            </li>
                            <li>
                                <input type="text" name="type" placeholder="请输入型号规格"/>
                            </li>
                            <li>
                                <select name="useStatus" >
                                    <option value="">请选择操作状态</option>
                                    <option value="0">已入库</option>
                                    <option value="1">已出库</option>
                                </select>
                            </li>
                            <li>
                                <select name="deviceStatus" id="deviceStaus">
                                    <option value="">请选择仪器状态</option>
                                    <option value="0">正常</option>
                                    <option value="1">报废</option>
                                    <option value="2">维修</option>
                                    <option value="3">无效</option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="device:information:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="device:information:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="device:information:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="device:information:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var detailFlag = [[${@permission.hasPermi('device:information:detail')}]];
        var editFlag = [[${@permission.hasPermi('device:information:edit')}]];
        var removeFlag = [[${@permission.hasPermi('device:information:remove')}]];
        var deviceStatus = [[${@dict.getType('tmd_device_status')}]];
        var useStatus = [[${@dict.getType('tmd_device_use_status')}]];

        var prefix = ctx + "device/information";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                detailUrl: prefix + "/detail/{id}",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "仪器信息",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '编号',
                    visible: false
                },
                    {
                        title: "编号",
                        formatter: function (value, row, index) {
                            return $.table.serialNumber(index);
                        },
                        align: 'center',
                    },
                {
                    field: 'deviceName',
                    title: '仪器名称',
                    align: 'center',
                },
                {
                    field: 'type',
                    title: '型号规格',
                    align: 'center',
                },
                {
                    field: 'savePosition',
                    title: '存放位置',
                    align: 'center',
                },
                {
                    field: 'createPerson',
                    title: '创建人',
                    align: 'center',
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    formatter: $.table.datetimeFormatter,
                    align: 'center',
                },
                {
                    field: 'deviceStatus',
                    title: '仪器状态',
                    align: 'center',
                    formatter: function (value) {
                        return $.table.selectDictLabel(deviceStatus, value);
                    },
                },
                {
                    field: 'deptId',
                    title: '所属部门id 部门id',
                    visible: false
                },
                {
                    field: 'mainAim',
                    title: '主要技术指标',
                    visible: false
                },
                {
                    field: 'valid',
                    title: '鉴定有效期 有效天数',
                    visible: false
                },
                {
                    field: 'useStatus',
                    title: '使用状态',
                    visible: true,
                    align: 'center',
                    formatter: function (value) {
                        return $.table.selectDictLabel(useStatus, value);
                    },
                },
                {
                    field: 'file',
                    title: '附件 附件',
                    visible: false,
                    align: 'center',
                },
                {
                    field: 'text',
                    title: '备注 备注',
                    visible: false,
                    align: 'center',
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {

                        //查看
                        if (row.useStatus === 0){
                            var actions = [];
                            actions.push('<a class="btn btn-success btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看</a> ');
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                            actions.push('<a class="btn btn-success btn-xs"  href="javascript:void(0)" onclick = "dfs(\'' + row.id + '\')"  id="dfs '+ row.id + '"  ><i class="fa fa-edit"></i>出库</a> ');
                        }else{
                            var actions = [];
                            actions.push('<a class="btn btn-success btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看</a> ');
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)"  disabled="true"  id="dfs '+ row.id + '" ><i class="fa fa-edit"></i>出库</a> ');

                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
    </script>

    <script>
        function dfs(id) {
            $.ajax({
                url: prefix + '/dfs',
                type: 'post',
                data: {
                    id: id
                },
                success: function(response) {
                    alert('出库成功');
                    location.reload();
                },
                error: function(xhr, status, error) {
                    alert('出库失败' + xhr.responseText);
                },
            })
        }
    </script>

</body>
</html>